<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">


			<head>
            <title>Project Cronos-Config</title>
            <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
            
             <!--   <link rel='stylesheet' href='style.css' type='text/css' media='screen' />  -->
               <!-- <link rel='icon' href='images/cronos.ico' type='image/x-icon' />-->
                <link rel='icon' href='images/arigel.ico' type='image/x-icon' />

            </head>

            <body><div id='outer'><div id='header'><div align='right'><img src='images/content/bug.png' title='Hic Sunt Dracones' />&nbsp;� version</div><br><br><a href='main.php'><img src='images/cronos_tp.jpg' alt='EightyThree Logo' title='Go to Main Page' /></a></div>
            <br /><br />
            </div>
            
            </div>
             <div style='font-size : 28px;font-style : normal;padding-bottom:10px;'>Install Cronos</div><br />
<?php
	$d_type=$_REQUEST["dbtype"];
	$d_hname=$_REQUEST["dbhost"];
	$d_name=$_REQUEST["dbname"];
	$d_uname=$_REQUEST["dbuser"];
	$d_pass=$_REQUEST["dbpassword"];
	$d_suname=$_REQUEST["dbsuperuser"];
	$d_spass=$_REQUEST["dbsuperpassword"];
	//$f_handle=shell_exec('cat> /var/www/projectcronos/config.txt');
	//echo 'kjkjjjjkj'.$f_handle.'oioi';
	$f_handle=fopen("config.txt","w");
	if($f_handle)
	{
		$text=$d_type. "\n".$d_hname."\n".$d_name."\n".$d_uname."\n".$d_pass."\n";
		fwrite($f_handle,$text);
		echo "<b>Config File Created.</b></br>";
		fclose($f_handle);
/*$useragent = $_SERVER["HTTP_USER_AGENT"];
		
ECHO $useragent;

if (stristr($useragent,‘Win’)) {
    $os=‘Win’;
} else if (stristr($useragent,‘Mac’)) {
    $os=‘Mac’;
} else if (stristr($useragent,‘Linux’)) {
    $os=‘Linux’;
} else if (stristr($useragent,‘Unix’)) {
    $os=‘Unix’;
} else {
    $os=‘Other’;
}
echo 'OS is '.$os;*/

		$con=mysql_connect('localhost',"root","asdasd") or die("Couldnt Connect to the server.");
		echo "<b>Connection with root Established.</b><br>";
		$sql="CREATE USER '".$d_uname."'@'".$d_hname."' IDENTIFIED BY '".$d_pass."';";
		$query=mysql_query($sql) or die("Couldnt Create The User.". mysql_error() . "<br>");
		echo "<b>New User Created.</b><br>";
		$sql="GRANT ALL PRIVILEGES ON *.* TO '".$d_uname."'@'".$d_hname."' WITH GRANT OPTION;";;
		$query=mysql_query($sql) or die("Couldnt Create The User.");
		echo "<b>Privileges Granted.</b><br>";
		$con=mysql_connect($d_hname,$d_uname,$d_pass) or die("Couldnt Connect to the server.");
		echo "<b>Connection Established with new username.</b><br>";
		$sql = "CREATE DATABASE ".$d_name.";";
		if (mysql_query($sql, $con)) {
		echo "Database <b>".$d_name."</b> Created Successfully\n";
		$sql="CREATE TABLE `".$d_name."`.`address` (
  					`add_id` int UNSIGNED NOT NULL AUTO_INCREMENT,
  					`name` char  NOT NULL,
  					`nick_name` char ,
  					`dob` date  NOT NULL,
  					`gender` char ,
  					`work_mail` varchar(100) ,
  					`hom_mail` varchar(100) ,
  					`address` varchar(100) ,
  					`city` varchar(100) ,
  					`state` varchar(100) ,
  					`zip` integer ,
  					`country` varchar(100) ,
  					`m_num` integer ,
  					`h_num` integer ,
  					`fax_num` integer ,
  					`compny` varchar(100) ,
  					`dept` varchar(100) ,
  					`o_num` integer ,
  					PRIMARY KEY (`add_id`)
				)";
				$query=mysql_query($sql) or die("Error");
				echo "<b>Address book created.</b><br>";
				
				$sql="CREATE TABLE `".$d_name."`.`calendar` (
  					`seq_no` int UNSIGNED NOT NULL AUTO_INCREMENT,
  					`dt` date  NOT NULL,
  					`appo` varchar(100) ,
  					`priority` char ,
  					`disc` varchar(100) ,
  					PRIMARY KEY (`seq_no`) 
				)";
				$query=mysql_query($sql) or die("Error");
				echo "<b>Calendar created.</b><br>";
				
				$sql="CREATE TABLE `".$d_name."`.`thngs_to_do` (
  					`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
  					`title` varchar(100)  NOT NULL,
  					`strt_date` date NOT NULL,
  					`end_date` date NOT NULL,
  					`time` time ,
  					`priority` char ,
  					`status` char ,
  					`disc` varchar(100) ,
  					PRIMARY KEY (`id`) 
				)";
				$query=mysql_query($sql) or die("Error");
				echo "<b>Things to do table created.</b><br>";
	$sql ="create table `".$d_name."`.`wikimodule` ( 
		page_number int not null ,
		page_name varchar(100) not null ,
		page_creation_date date not null ,
		page_creation_time time not null ,
		page_modified_date date not null ,
		page_modified_time time not null ,
		page_changed_by varchar(100) not null ,
		page_content varchar(100) not null ,
		page_label varchar(100) not null)";
	$query=mysql_query($sql) or die("Error");
echo "<b>Wiki Table created.</b><br>";



$sql ="create table `".$d_name."`.`filemag`(
		file_id int primary key,
		file_name varchar(100), 		
		date_creat date,				
		date_modifi	date, 	 			
		time_creat time, 				
		time_modifi	time, 				
		modifi_by int, 			
		stored_address varchar(100), 				
		file_size int, 			
		file_type varchar(100), 
		description	varchar(100), 				
		modifi_description varchar(500), 
		owner_id int )";
$query=mysql_query($sql) or die("Error");
echo "<b>File Table created.</b><br>";


$sql ="create table `".$d_name."`.`notes` (
	   date1 date  not null ,
	   time1 time not null ,
	   notes varchar(10000) not null ,
	   purpose varchar(500))";
$query=mysql_query($sql) or die("Error");
echo "<b>Notes table created.</b><br>";

$sql ="create table `".$d_name."`.`appointment` (
	   date1 date not null,
	   time1 time not null,
	   duration time not null,
	   notes varchar(1000) ,
	   location varchar(100),
	   reminder varchar(100) not null,
	   reminder_minutes time,
	   added_to_outlook varchar(500))";
$query=mysql_query($sql) or die("Error");
echo "<b>Appointment Table created.</b><br>";
$sql ="create table `".$d_name."`.`login` (
		u_name varchar(50), 
		pass varchar(100))";
$query=mysql_query($sql) or die("Error");
echo "<b>Login table created.</b><br>";

$sql= "insert into `".$d_name."`.`login` values('".$d_suname."','".$d_spass ."')";
$query=mysql_query($sql) or die("Error");

echo "<b>Superuser entry created in login table.</b><br>";

$sql ="Create table `".$d_name."`.`url` (
		url_id integer  primary key,
		url varchar(100))";
$query=mysql_query($sql) or die("Error");

$sql ="create table `".$d_name."`.`subscribed` (
	   user_id integer primary key ,
	   url_id integer references url ,
	   number_of_articles integer)";
$query=mysql_query($sql) or die("Error");

$sql ="create table `".$d_name."`.`final`(
		user_id integer  primary key,
		url_id integer references url,
		url varchar(100) ,
		number_of_articles integer ,
		title varchar(100) not null,
		description varchar(1000) not null,
		creation_date date not null, 
		last_refresh date)";
$query=mysql_query($sql) or die("Error");
echo "<b>RSS Tables Created.</b><br>";

//Now create PHP Wiki Tables
		$sql="mysql -uroot -pasdasd ".$d_name." </var/www/phpwiki/schemas/schema.mysql";
		shell_exec($sql);
		echo "<b>Wiki Tables created</b><br />";
		}
		else {
		echo 'Error creating database: <b>' . mysql_error() . "</b>\n";
		}
		mysql_close($con);
	}
	else
	{
		echo "Cronos not installed";
	}
	
?>
			<form action='index.php' method='post'>  
			<input type='submit' value='Next'/>
			</form>
				<br />	<br />	
            <div style='border-top:5px solid #000'> 
            <div style='float:right;'><a href='http://www.arigel.com' title='Go to Arigel Website'><img src='images/footer/logo.png' border=0 alt='Arigel Open Source logo' /></a></div>

            </div>
            <!-- CRONOS - 1983 -->
            <!-- This is version 0.1 Beta -->
            
            <!-- CRONOS is released under GPL v3. CRONOS is owned by Arigel -->
            </body>
            </html>